package com.ianswer.px.user.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ianswer.common.orm.PublicDao;
import com.ianswer.px.user.entity.UsersFigure;
import com.ianswer.px.user.service.UserFigureService;

@Service("userFigureService")
public class UserFigureServiceImpl implements UserFigureService {

	@Resource(name = "publicDao")
	private PublicDao publicDao;
	
	@Override
	public UsersFigure get(long userId) {
		return publicDao.querySingle("usersFigure.get", userId);
	}
	
	@Override
	public void insert(UsersFigure u) {
		publicDao.insert("usersFigure.insert", u);
	}
	
	@Override
	public void update(UsersFigure u) {
		publicDao.update("usersFigure.update", u);
	}
	
	public void save(UsersFigure u) {
		UsersFigure db = get(u.getUserId());
		
		if (db != null) {
			update(u);
		} else {
			insert(u);
		}
	}
}
